﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebService_Newstore.DAO
{
    public class ParametreDAO : BaseDAO
    {
        public int id_param { get; set; }
        public int id_confAdminBP { get; set; }
        public int id_confPrepa { get; set; }
        public int id_confCmd { get; set; }
        public int id_confRecep { get; set; }

        public ParametreDAO()
        {
            using (newStoreContext = new newStoreEntities())
            {
                try
                {
                    var paramQuery = from parametre in newStoreContext.parametres
                                    select parametre;

                    if (paramQuery.LongCount() == 0)
                    {
                        //On instancie un userDAO vide pour faire remonter l'erreur au niveau du controller
                        this.id_param = 0;
                        this.id_confAdminBP = 0;
                        this.id_confPrepa = 0;
                        this.id_confCmd = 0;
                        this.id_confRecep = 0;
                    }

                    foreach (var param in paramQuery)
                    {
                        //On instancie le paramDAO
                        this.id_param = param.id_param;
                        this.id_confAdminBP = param.id_conf_AdminBP;
                        this.id_confPrepa = param.id_conf_Prepa;
                        this.id_confCmd = param.id_conf_Cmd;
                        this.id_confRecep = param.id_conf_Recep;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.ReadLine();
                }
            }
        }
    }
}